import Blob from './vendor/Blob.js';
import Export2Excel from './vendor/Export2Excel.js';

function leadOutExcel (
  tHeader = [],
  filterVal = [],
  tableData = [],
  name = ''
) {
  let that = this;
  require.ensure ([], () => {
    const {export_json_to_excel} = require ('./vendor/Export2Excel'); //这里必须使用绝对路径
    const data = formatJson (filterVal, tableData);
    export_json_to_excel (tHeader, data, name);
  });
  return new Promise (resolve => {
    resolve ('ok');
  });
}

function formatJson (filterVal, jsonData) {
  return jsonData.map (v => filterVal.map (j => v[j]));
}

export {leadOutExcel};
